using System;

namespace umbSearch.businessLogic
{
	/// <summary>
	/// Summary description for IndexText.
	/// </summary>
	public class IndexText : interfaces.IUmbracoSearchFileFilter
	{
		public IndexText()
		{
			//
			// TODO: Add constructor logic here
			//
		}
		#region IUmbracoSearchFileFilter Members

		public string[] extensions
		{
			get
			{
				string[] _extensions = {"txt"};
				return _extensions;
			}
		}

		public string returnText(string FullPathToFile)
		{
			try 
			{
				if (System.IO.File.Exists(FullPathToFile)) 
				{
					try 
					{
						System.IO.StreamReader re = System.IO.File.OpenText(FullPathToFile);				
						string content = re.ReadToEnd();
						re.Close();
						return content;
					} 
					catch (Exception ee) 
					{
						throw new Exception("Error indexing file '" + FullPathToFile + "'",ee);
					}
				}
				else
					throw new Exception("Error indexing file '" + FullPathToFile + "': File doesn't exists");
			} 
			catch (Exception ee)
			{
				throw new Exception("Error indexing file '" + FullPathToFile + "'",ee);
			}
		}

		#endregion
	}
}
